package leetcode.code1691;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {
	public int maxHeight(int[][] cuboids) {
		for (int i = 0; i < cuboids.length; i++) {
			Arrays.sort(cuboids[i]);
		}
		Arrays.sort(cuboids, (a, b) -> a[0] == b[0] ? a[1] == b[1] ? a[2] - b[2] : a[1] - b[1] : a[0] - b[0]);
		int[] max = new int[cuboids.length];
		int ans = 0;
		for (int i = 0; i < cuboids.length; i++) {
			max[i] = cuboids[i][2];
			for (int j = 0; j < i; j++) {
				if (cuboids[i][0] >= cuboids[j][0] && cuboids[i][1] >= cuboids[j][1]
						&& cuboids[i][2] >= cuboids[j][2]) {
					max[i] = Math.max(max[i], max[j] + cuboids[i][2]);
				}
			}
			ans = Math.max(ans, max[i]);
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(190, maxHeight(H.str2array1("[[50,45,20],[95,37,53],[45,23,12]]")));
		H.compare(76, maxHeight(H.str2array1("[[38,25,45],[76,35,3]]")));
		H.compare(102, maxHeight(H.str2array1("[[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
